package com.ruoyi.project.jiaqin.quotation.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.jiaqin.area.domain.QuotationClassArea;
import com.ruoyi.project.jiaqin.area.service.IQuotationClassAreaService;
import com.ruoyi.project.jiaqin.company.domain.Company;
import com.ruoyi.project.jiaqin.company.service.ICompanyService;
import com.ruoyi.project.jiaqin.followmember.domain.JiaqinFollowMember;
import com.ruoyi.project.jiaqin.followmember.service.IJiaqinFollowMemberService;
import com.ruoyi.project.jiaqin.quotation.domain.Quotation;
import com.ruoyi.project.jiaqin.quotation.domain.QuotationSelectedBean;
import com.ruoyi.project.jiaqin.quotation.domain.QuotationTrend;
import com.ruoyi.project.jiaqin.quotation.mapper.QuotationMapper;
import com.ruoyi.project.jiaqin.quotation.service.IQuotationService;
import com.ruoyi.project.jiaqin.quotationclass.domain.QuotationClass;
import com.ruoyi.project.jiaqin.quotationclass.service.IQuotationClassService;
import com.ruoyi.project.jiaqin.quotationcollect.domain.QuotationCollect;
import com.ruoyi.project.jiaqin.quotationcollect.mapper.QuotationCollectMapper;
import com.ruoyi.project.jiaqin.quotationlikes.domain.MemberQuotationLikes;
import com.ruoyi.project.jiaqin.quotationlikes.mapper.MemberQuotationLikesMapper;
import com.ruoyi.project.jiaqin.quotationlikes.service.IMemberQuotationLikesService;
import com.ruoyi.project.jiaqin.thrclasstrend.domain.ThrClassTrend;
import com.ruoyi.project.jiaqin.thrclasstrend.mapper.ThrClassTrendMapper;
import com.ruoyi.project.jiaqin.twoclasstrend.domain.TwoClassTrend;
import com.ruoyi.project.jiaqin.twoclasstrend.mapper.TwoClassTrendMapper;
import com.ruoyi.project.jiaqin.val.domain.ClassAttrVal;
import com.ruoyi.project.jiaqin.val.mapper.ClassAttrValMapper;
import com.ruoyi.project.system.member.domain.Member;
import com.ruoyi.project.system.member.mapper.MemberMapper;
import com.ruoyi.project.system.member.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

/**
 * 行情Service业务层处理
 *
 * @author admin
 * @date 2020-12-21
 */
@Service
public class QuotationServiceImpl implements IQuotationService
{
    @Autowired
    private QuotationMapper quotationMapper;

    @Autowired
    private ClassAttrValMapper classAttrValMapper;

    @Autowired
    private TwoClassTrendMapper twoClassTrendMapper;

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private ThrClassTrendMapper thrClassTrendMapper;
    @Autowired
    private MemberQuotationLikesMapper memberQuotationLikesMapper;
    @Autowired
    private IJiaqinFollowMemberService jiaqinFollowMemberService;
    @Autowired
    private IQuotationService quotationService;
    @Autowired
    private IQuotationClassService quotationClassService;
    @Autowired
    private IMemberService memberService;
    @Autowired
    private IMemberQuotationLikesService iMemberQuotationLikesService;

    /**
     * 查询行情
     * @param id 行情ID
     * @return 行情
     */
    @Override
    public Quotation selectQuotationById(String id)
    {
        this.addQuotationLooksById(id);
        return quotationMapper.selectQuotationById(id);
    }

    /**
     * 增加浏览量
     * @param id 行情ID
     * @return 行情
     */
    @Override
    public int addQuotationLooksById(String id)
    {
        return quotationMapper.addQuotationLooksById(id);
    }

    @Override
    public int unlikesQuotationLin(MemberQuotationLikes memberQuotationLikes) {
        return quotationMapper.unlikesQuotationLin(memberQuotationLikes);
    }

    @Override
    public int likesQuotationLin(MemberQuotationLikes memberQuotationLikes) {
        return quotationMapper.likesQuotationLin(memberQuotationLikes);
    }

    /**
     * 定时任务，每日凌晨两点统计前一天的二级分类 均价 并更新到二级分类表
     * @return
     */
    @Override
    @Transactional
    public Integer twoClassAvgStatistic() {
        //时间 2021-01-09 02：00：00 查询 二级分类ID，今日(01-08)均价,前一日(01-07)均价
        List<TwoClassTrend> list = quotationMapper.getTwoClassTodayAndLastdayAvg();
        for (TwoClassTrend tct: list) {
            if(tct.getTodayAvgPrice().compareTo(new BigDecimal(0.00)) == 0 && tct.getLastdayAvgPrice().compareTo(new BigDecimal(0.00)) == 0){
                //01-08 为00.00   01-07 为00.00
                tct.setWavePerc(new BigDecimal(0.00));
                tct.setWavePrice(new BigDecimal(0.00));
                tct.setStatus(0);//趋势平稳
                tct.setId(UUID.randomUUID().toString().replace("-",""));
            }
            if(tct.getTodayAvgPrice().compareTo(new BigDecimal(0.00)) == 0 && tct.getLastdayAvgPrice().compareTo(new BigDecimal(0.00)) != 0){
                //01-08 为00.00 没有人发布过行情 昨天有人发过   01-07 不为00.00
                tct.setTodayAvgPrice(tct.getLastdayAvgPrice());//设计今天的价格和昨天价格一样
                tct.setWavePerc(new BigDecimal(0.00));
                tct.setWavePrice(new BigDecimal(0.00));
                tct.setStatus(0);
                tct.setId(UUID.randomUUID().toString().replace("-",""));
            }
            if(tct.getTodayAvgPrice().compareTo(new BigDecimal(0.00)) != 0 && tct.getLastdayAvgPrice().compareTo(new BigDecimal(0.00)) == 0){
                //01-08 不为00.00 今天发布过行情 昨天没人发过   01-07 为00.00
                tct.setWavePerc(new BigDecimal(999.00));
                tct.setWavePrice(new BigDecimal(999.00));
                tct.setStatus(1);
                tct.setId(UUID.randomUUID().toString().replace("-",""));
            }
            if(tct.getTodayAvgPrice().compareTo(new BigDecimal(0.00)) != 0 && tct.getLastdayAvgPrice().compareTo(new BigDecimal(0.00)) != 0){
                //01-08 昨天有人发布,今天也有人发布
                //计算波动百分比
                BigDecimal cha = tct.getTodayAvgPrice().subtract(tct.getLastdayAvgPrice());
                tct.setWavePrice(cha);//计算
                //如果差值等于0
                if(cha.compareTo(new BigDecimal(0))==0){
                    //昨天和今天价格相同
                    tct.setWavePerc(new BigDecimal(0.00));
                    tct.setStatus(0);
                }else if(cha.compareTo(new BigDecimal(0)) == 1){
                    //昨天和今天价格不同 差大于零
                    tct.setWavePerc(tct.getTodayAvgPrice()
                            .subtract(tct.getLastdayAvgPrice())
                            .divide(tct.getLastdayAvgPrice(),4,BigDecimal.ROUND_UP)
                            .multiply(new BigDecimal(100)));
                    tct.setStatus(1);
                }else{
                    //差小于零
                    tct.setWavePerc(tct.getTodayAvgPrice()
                            .subtract(tct.getLastdayAvgPrice())
                            .divide(tct.getLastdayAvgPrice(),4,BigDecimal.ROUND_UP)
                            .multiply(new BigDecimal(100)));
                    tct.setStatus(2);
                }
                tct.setId(UUID.randomUUID().toString().replace("-",""));
            }
        }
        //批量插入二级分类趋势
        return twoClassTrendMapper.batchTwoClassTrend(list);
    }

    @Override
    public Integer thrClassAvgStatistic() {
        //时间 2021-01-09 02：00：00 查询 三级分类ID，今日(01-08)均价,前一日(01-07)均价
        List<ThrClassTrend> list = quotationMapper.getThrClassTodayAndLastdayAvg();
        for (ThrClassTrend tct: list) {
            if(tct.getTodayAvgPrice().compareTo(new BigDecimal(0.00)) == 0 && tct.getLastdayAvgPrice().compareTo(new BigDecimal(0.00)) == 0){
                //01-08 为00.00   01-07 为00.00
                tct.setWavePerc(new BigDecimal(0.00));
                tct.setWavePrice(new BigDecimal(0.00));
                tct.setStatus(0);//趋势平稳
                tct.setId(UUID.randomUUID().toString().replace("-",""));
            }
            if(tct.getTodayAvgPrice().compareTo(new BigDecimal(0.00)) == 0 && tct.getLastdayAvgPrice().compareTo(new BigDecimal(0.00)) != 0){
                //01-08 为00.00 没有人发布过行情 昨天有人发过   01-07 不为00.00
                tct.setTodayAvgPrice(tct.getLastdayAvgPrice());//设计今天的价格和昨天价格一样
                tct.setWavePerc(new BigDecimal(0.00));
                tct.setWavePrice(new BigDecimal(0.00));
                tct.setStatus(0);
                tct.setId(UUID.randomUUID().toString().replace("-",""));
            }
            if(tct.getTodayAvgPrice().compareTo(new BigDecimal(0.00)) != 0 && tct.getLastdayAvgPrice().compareTo(new BigDecimal(0.00)) == 0){
                //01-08 不为00.00 今天发布过行情 昨天没人发过   01-07 为00.00
                tct.setWavePerc(new BigDecimal(999.00));
                tct.setWavePrice(new BigDecimal(999.00));
                tct.setStatus(1);
                tct.setId(UUID.randomUUID().toString().replace("-",""));
            }
            if(tct.getTodayAvgPrice().compareTo(new BigDecimal(0.00)) != 0 && tct.getLastdayAvgPrice().compareTo(new BigDecimal(0.00)) != 0){
                //01-08 昨天有人发布,今天也有人发布
                //计算波动百分比
                BigDecimal cha = tct.getTodayAvgPrice().subtract(tct.getLastdayAvgPrice());
                tct.setWavePrice(cha);//计算
                //如果差值等于0
                if(cha.compareTo(new BigDecimal(0))==0){
                    //昨天和今天价格相同
                    tct.setWavePerc(new BigDecimal(0.00));
                    tct.setStatus(0);
                }else if(cha.compareTo(new BigDecimal(0)) == 1){
                    //昨天和今天价格不同 差大于零
                    tct.setWavePerc(tct.getTodayAvgPrice()
                            .subtract(tct.getLastdayAvgPrice())
                            .divide(tct.getLastdayAvgPrice(),4,BigDecimal.ROUND_UP)
                            .multiply(new BigDecimal(100)));
                    tct.setStatus(1);
                }else{
                    //差小于零
                    tct.setWavePerc(tct.getTodayAvgPrice()
                            .subtract(tct.getLastdayAvgPrice())
                            .divide(tct.getLastdayAvgPrice(),4,BigDecimal.ROUND_UP)
                            .multiply(new BigDecimal(100)));
                    tct.setStatus(2);
                }
                tct.setId(UUID.randomUUID().toString().replace("-",""));
            }
        }
        //批量插入三级分类趋势
        return thrClassTrendMapper.batchThrClassTrend(list);
    }

    @Override
    public List<Quotation> selectQuotationFive() {
        return quotationMapper.selectQuotationFive();
    }

    @Override
    public Quotation selectQuotationByTwoId(String memberId, String classIdThr) {
        return quotationMapper.selectQuotationByTwoId(memberId,classIdThr);
    }

    @Autowired
    private IQuotationClassAreaService quotationClassAreaService;
    /**
     * 查询行情列表
     * @param quotation 行情
     * @return 行情
     */
    @Override
    public List<Quotation> selectQuotationList(Quotation quotation)
    {
        List<Quotation> list = quotationMapper.selectQuotationList(quotation);
        for (Quotation q:list) {
            List<ClassAttrVal> listAttrVals = new ArrayList<>();
            if (q.getAttrVals() != null) {
                String[] srr = q.getAttrVals().split(",");
                for (String s:srr) {
                    //根基属性值ID查询属性值对象
                    ClassAttrVal classAttrVal = classAttrValMapper.selectClassAttrValById(s);
                    listAttrVals.add(classAttrVal);
                }
                q.setAttrValList(listAttrVals);
            }


            // 产地名
            QuotationClassArea quotationClassArea = quotationClassAreaService.selectQuotationClassAreaById(q.getClassAreaId());
            if (quotationClassArea != null) {
                q.setClassAreaName(quotationClassArea.getName());
            }
        }
        return list;
    }

    @Override
    public List<QuotationTrend> getTrendForTwoQClass(String twoClassId) {
        return quotationMapper.getTrendForTwoQClass(twoClassId);
    }

    @Override
    public PageInfo selectQuotationListByThrClassId(Integer pageNum,Integer pageSize ,String thrClassId,String memberId) {
        Quotation quotation = new Quotation();
        quotation.setClassIdThr(thrClassId);
        PageHelper.startPage(pageNum,pageSize);
        List<Quotation> list = quotationMapper.selectQuotationList(quotation);
        if(memberId != null){
            for (Quotation q:list){
                if(memberQuotationLikesMapper.selectMemberQuotationLikesById(memberId,q.getId())==null){
                    q.setFlagLikes(false);
                }else{
                    q.setFlagLikes(true);
                }
            }
        }
        PageInfo<Quotation> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增行情
     * @param quotation 行情
     * @return 结果
     */
    @Override
    public int insertQuotation(Quotation quotation)
    {
        quotation.setId(UUID.randomUUID().toString().replace("-",""));
        quotation.setReleaseDate(new Date());
        return quotationMapper.insertQuotation(quotation);
    }

    /**
     * 修改行情
     *
     * @param quotation 行情
     * @return 结果
     */
    @Override
    public int updateQuotation(Quotation quotation)
    {
        return quotationMapper.updateQuotation(quotation);
    }

    /**
     * 删除行情对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteQuotationByIds(String ids)
    {
        return quotationMapper.deleteQuotationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除行情信息
     *
     * @param id 行情ID
     * @return 结果
     */
    @Override
    public int deleteQuotationById(String id)
    {
        return quotationMapper.deleteQuotationById(id);
    }

    @Override
    @Transactional
    public int likesQuotation(String memberId, String quotationId) {
        MemberQuotationLikes memberQuotationLikes = new MemberQuotationLikes();
        memberQuotationLikes.setMemberId(memberId);
        memberQuotationLikes.setQuotationId(quotationId);
        memberQuotationLikesMapper.insertMemberQuotationLikes(memberQuotationLikes);
        return quotationMapper.updateLikes(1L,quotationId);
    }

    @Override
    @Transactional
    public int unlikesQuotation(String memberId, String quotationId) {
        return quotationMapper.updateLikes(-1L,quotationId);
    }

    @Autowired
    private QuotationCollectMapper quotationCollectMapper;
    @Autowired
    private ICompanyService companyService;
    @Override
    public PageInfo<QuotationCollect> getQuotation(Integer pageNum, Integer pageSize, String memberId) {
//        // 查询我关注的人
//        JiaqinFollowMember followMember = new JiaqinFollowMember();
//        followMember.setMemberId(memberId);
//        List<JiaqinFollowMember> followMemberList = jiaqinFollowMemberService.selectJiaqinFollowMemberList(followMember);
//
////        List<Quotation> arrayList = new ArrayList<>();
//        List<Object> arrayList = new ArrayList<>();
//
//        if (followMemberList != null && followMemberList.size() != 0) {
//            for (JiaqinFollowMember JFM : followMemberList) {
//                // 查询我关注的人发布的行情
//                PageHelper.startPage(pageNum,pageSize);
//                List<Quotation> quotationList = quotationMapper.getQuotation(JFM.getFollowMemberId());
//
//                if (quotationList != null && quotationList.size() != 0) {
//                    for (Quotation Q : quotationList) {
//                        // 关联我关注的人发布的行情信息
//                        Quotation quotationById = quotationMapper.selectQuotationById(Q.getId());
//                        if (quotationById != null) {
//                            // Q.setQuotation(quotationById);
//                            QuotationClass classByIdTwo = quotationClassService.selectQuotationClassById(quotationById.getClassIdTwo());
//                            QuotationClass classByIdThr = quotationClassService.selectQuotationClassById(quotationById.getClassIdThr());
//                            if (classByIdTwo != null) {
//                                Q.setTwoClassName(classByIdTwo.getName());
//                            }
//                            if (classByIdThr != null) {
//                                Q.setThrClassName(classByIdThr.getName());
//                                Q.setThrClassUnit(classByIdThr.getUnit());
//                            }
//                            Member memberById = memberService.selectMemberById(quotationById.getMemberId());
//                            if (memberById != null) {
//                                Q.setMemberName(memberById.getUsername());
//                            }
//                        }
//                    }
//                }
////                arrayList = quotationList;
//                arrayList.add(quotationList);
//            }
//        }
//        PageInfo<Object> pageInfo = new PageInfo<>(arrayList);
//        return pageInfo;
        PageHelper.startPage(pageNum,pageSize);
        List<QuotationCollect> list = quotationCollectMapper.selectQuotationCollectByMemberId(memberId);
        if(list != null && list.size()!= 0){
            for (QuotationCollect QC :list) {
                Quotation quotationById = quotationService.selectQuotationById(QC.getQuotationId());
                if(quotationById != null) {
                    Member memberById = memberService.selectMemberById(quotationById.getMemberId());
                    QC.setQuotation(quotationById);
                    QuotationClass quotationClass = quotationClassService.selectQuotationClassById(quotationById.getClassIdThr());
                    if (quotationClass != null) {
                        quotationById.setThrClassName(quotationClass.getName());
                        quotationById.setThrClassUnit(quotationClass.getUnit());
                    }
                    String[] srr = quotationById.getAttrVals().split(",");
                    ClassAttrVal classAttrValById = classAttrValMapper.selectClassAttrValById(srr[0]);
                    if (classAttrValById != null) {
                        quotationById.setClassAttribute(classAttrValById.getAttrVal());
                    }
                    if (memberById != null) {
                        Company company = companyService.selectCompanyByMemberId(memberById.getId());
                        if (company != null) {
                            quotationById.setMemberName(company.getCompanyName());
                            quotationById.setHeadpic(company.getCompanyAvatar());
                        } else {
                            quotationById.setMemberName(memberById.getUsername());
                            quotationById.setHeadpic(memberById.getHeadpic());
                        }
                    }
                }
            }
        }
        PageInfo<QuotationCollect> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Quotation> findQuotationList(Quotation quotation) {
        return quotationMapper.findQuotationList(quotation);
    }

    @Override
    public PageInfo<Object> getQuotationReleaseByParams(Integer pageNum, Integer pageSize, QuotationSelectedBean bean) {

        Member currentMember = memberMapper.selectMemberById(bean.getMemberId());
        BigDecimal endLon = currentMember.getLongitude();
        BigDecimal endLat = currentMember.getLatitude();
        bean.setLatitude(endLat);
        bean.setLongitude(endLon);
        List<Quotation> list = new ArrayList<>();
        PageHelper.startPage(pageNum,pageSize);
        if (bean.getType().length() <= 0){
            bean.setType("1");//默认人气排序
        }
        if (Integer.parseInt(bean.getType()) == 1){
            list = quotationMapper.getQuotationReleaseByParams(bean);
        }else if (Integer.parseInt(bean.getType()) == 3){

            list = quotationMapper.getQuotationReleaseByParamsDescDistance(bean);
        } else{
            list = quotationMapper.getQuotationReleaseByParamsDescTime(bean);
        }
        List<Object>resultList = new ArrayList<>();
        //拿到Quotations，循环关联查询
        for (Quotation quotation : list){
            Map map = JSON.parseObject(JSON.toJSONString(quotation), Map.class);

            MemberQuotationLikes memberQuotationLikes=  iMemberQuotationLikesService.selectMemberQuotationLikesById(bean.getMemberId(),quotation.getId());
            if (memberQuotationLikes == null){
                map.put("isLike","0");
            }else {
                map.put("isLike","1");
            }

            Member member = memberMapper.selectMemberById(quotation.getMemberId());
            BigDecimal startLon = BigDecimal.valueOf(0);
            BigDecimal startLat = BigDecimal.valueOf(0);
            Company company = companyService.selectCompanyByMemberId(quotation.getMemberId());
            if (company != null){
                startLon = company.getLongitude();
                startLat = company.getLatitude();
                map.put("companyId",company.getId());
                map.put("corporation",company.getCompanyName());
                map.put("headpic",company.getCompanyAvatar());
            }else {
                startLon = member.getLongitude();
                startLat = member.getLatitude();
                map.put("companyId","");
                map.put("corporation",member.getUsername());
                map.put("headpic",member.getHeadpic());
            }
            map.put("memberId",quotation.getMemberId());
//
//            double distance = DistanceUtils.getDistance(startLat.doubleValue(),endLat.doubleValue(),startLon.doubleValue(),endLat.doubleValue());
//
            map.put("distance",quotation.getDistance());
//            map.put("corporation",member.getCorporation());

            String arrtsStr = "";
            if (quotation.getAttrVals() != null) {
                String[] attrList = quotation.getAttrVals().split(",");

                for (int i = 0; i <attrList.length ; i++) {
                    String arrtId = attrList[i];
                    ClassAttrVal cv = classAttrValMapper.selectClassAttrValById(arrtId);
                    if (i == attrList.length - 1){
                        arrtsStr += cv.getAttrVal();
                    }else {
                        arrtsStr += cv.getAttrVal();
                        arrtsStr += ",";
                    }
                }
            }

            map.put("attrVal",arrtsStr);
            map.put("price",quotation.getPrice());
            map.put("province",quotation.getProvince());
            map.put("city",quotation.getCity());
            map.put("area",quotation.getArea());
            map.put("releaseDate",quotation.getReleaseDate());
            map.put("marketDynamic",quotation.getMarketDynamic());
            map.put("likes",quotation.getLikes());
            map.put("looks",quotation.getLooks());
            map.put("id",quotation.getId());
            map.put("status",quotation.getStatus());
            resultList.add(map);
        }
        PageInfo<Object> pageInfo = new PageInfo<>(resultList);
        return pageInfo;
    }

    @Override
    public PageInfo<Quotation> getQuotationListByMemberId(Integer pageNum, Integer pageSize, String memberId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Quotation> list = quotationMapper.getQuotationListByMemberId2(memberId);
        List<Quotation> newList = new ArrayList<Quotation>();
        Set<String> set = new HashSet<String>();
        for (Quotation Q : list) {
            String userId = Q.getMemberId();
            if (!set.contains(userId)) { //set中不包含重复的
                set.add(userId);
                String[] srr = Q.getAttrVals().split(",");
                ClassAttrVal classAttrValById = classAttrValMapper.selectClassAttrValById(srr[0]);
                if (classAttrValById != null) {
                    Q.setClassAttribute(classAttrValById.getAttrVal());
                }
                Company company = companyService.selectCompanyByMemberId(Q.getMemberId());
                Member member = memberService.selectMemberById(Q.getMemberId());
                if (company != null) {
                    Q.setIsCompany(1);
                    Q.setMemberName(company.getCompanyName());
                    Q.setHeadpic(company.getCompanyAvatar());
                } else {
                    Q.setIsCompany(0);
                    Q.setMemberName(member.getUsername());
                    Q.setHeadpic(member.getHeadpic());
                }
                Q.setMemberCompanyId(Q.getMemberId());
                newList.add(Q);
            }
            // 关注行情列表每一条数字提示
            JiaqinFollowMember followMember = jiaqinFollowMemberService.selectJiaqinFollowMemberByMemberIdAndToMemberId(memberId, userId);
            if (followMember != null && followMember.getQuotationNum() == 1) {
                List<Quotation> list1 = quotationMapper.getQuotationNumByMemberId(userId);
                Q.setQuotationNum(list1.size());;
            } else {
                Q.setQuotationNum(0);
            }
        }
        PageInfo<Quotation> pageInfo = new PageInfo<>(newList);
        return pageInfo;
    }

    @Override
    public List<Quotation> getQuotationListByMemberId2(String memberId) {
        return quotationMapper.getQuotationListByMemberId2(memberId);
    }

    @Override
    public PageInfo<Quotation> getFocusOnMarketByFollowMemberId(Integer pageNum, Integer pageSize, String followMemberId) {
        PageHelper.startPage(pageNum,pageSize);
        Quotation quotation = new Quotation();
        quotation.setMemberId(followMemberId);
        List<Quotation> list = quotationMapper.selectQuotationList(quotation);
        for (Quotation Q : list) {
            String[] srr = Q.getAttrVals().split(",");
            ClassAttrVal classAttrValById = classAttrValMapper.selectClassAttrValById(srr[0]);
            if (classAttrValById != null) {
                Q.setClassAttribute(classAttrValById.getAttrVal());
            }
            Company company = companyService.selectCompanyByMemberId(Q.getMemberId());
            Member member = memberService.selectMemberById(Q.getMemberId());
            if (company != null) {
                Q.setIsCompany(1);
                Q.setMemberName(company.getCompanyName());
                Q.setHeadpic(company.getCompanyAvatar());
                Q.setMemberCompanyId(Q.getMemberId());
            } else {
                Q.setIsCompany(0);
                Q.setMemberName(member.getUsername());
                Q.setHeadpic(member.getHeadpic());
                Q.setMemberCompanyId(Q.getMemberId());
            }

            // 取消关注行情数字提示
            JiaqinFollowMember followMember = new JiaqinFollowMember();
            followMember.setFollowMemberId(Q.getMemberId());
            List<JiaqinFollowMember> followMemberList = jiaqinFollowMemberService.selectJiaqinFollowMemberList(followMember);
            if (followMemberList.size() > 0) {
                for (JiaqinFollowMember JFM : followMemberList) {
                    JFM.setId(JFM.getId());
                    JFM.setQuotationNum(0);
                    jiaqinFollowMemberService.updateJiaqinFollowMember(JFM);
                }
            }

        }
        PageInfo<Quotation> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
